<template>
	<view class="tui-set-box">
		<tui-list-cell padding="0" :lineLeft="false" :arrow="true" @click="href()">
			<view class="tui-list-cell tui-info-box">
				<image :src="userinfo.headpic || '/static/images/missing-face.png'" class="avatar"></image>
				<view><text class="username">{{userinfo.username||'游客，去登录'}}</text></view>
			</view>
		</tui-list-cell>
		<view class="tui-mtop">
			<tui-list-cell padding="0" :lineLeft="false" :arrow="true" @click="logout()">
				<view class="tui-list-cell">
					退出登录
				</view>
			</tui-list-cell>
		</view>
	</view>
</template>
<script>
	var _self;
	import $C from '@/common/config'
	import tuiListCell from '@/components/tui/tui-list-cell';
	import tuiIcon from "@/components/tui/tui-icon"
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		components: {
			tuiIcon,
			tuiListCell
		},
		data() {
			return {
				is_num: false,
				userinfo: '',
				userList: [],
				myInfo: '',
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
				getimg: this.$getimg,
				maskState: 0,
				vipInfo: [],
				config: [],
				vip: 0,
				order_total: [],
				is_mobile: false
			}
		},
		onLoad() {
		},
		watch(){},
		onShow() {
			let token = uni.getStorageSync('token') || '';
			let my = uni.getStorageSync('my');
			if (my && token) {
				this.myInfo = my.data
				this.userinfo = my.data
			}
		},
		computed: {
			// 计算属性用于判断token是否为空
			hasToken() {
				return !!this.token;
			}
		},
		methods: {
			href() {
				let token = uni.getStorageSync('token') || '';
				let my = uni.getStorageSync('my');
				if (my && token) {} else {
					uni.navigateTo({
						url: "/pages/my/login",
						success: function(res) {
							console.log(res)
						}
					})
				}
			},
			logout() {
				uni.request({
					url: $C.api_url + 'api/user/admin/logout',
					method: 'GET',
					header: {
						satoken: uni.getStorageSync('token')
					},
					success: function(res3) {
						uni.removeStorageSync("token");
						uni.removeStorageSync("my");
						
						console.log(uni.getStorageSync("my"));
						uni.reLaunch({
							url: '/pages/my/my'
						})
					}
					,
					fail:function(err) {
						uni.removeStorageSync("token");
						uni.removeStorageSync("my");
						
						console.log(uni.getStorageSync("my"));
						uni.reLaunch({
							url: '/pages/my/my'
						})
					}
				});
			}
		}
	}
</script>
<style lang='scss'>
	.tui-set-box {
		padding-bottom: 20rpx;
		color: #333;
	}

	.tui-list-cell {
		display: flex;
		align-items: center;
		padding: 24rpx 30rpx;
		font-size: 30rpx;
	}

	.tui-info-box {
		font-size: 34rpx;
	}

	.avatar {
		width: 140rpx;
		height: 140rpx;
		margin-right: 20rpx;
		border: 5upx solid #fff;
		border-radius: 50%;
	}

	.tui-mtop {
		margin-top: 20rpx;
	}

	.tui-exit {
		padding: 100rpx 24rpx;
	}
</style>